package com.smile.chatview;

import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.smile.model.FriendInfo;

public class MyCellRenderer extends JLabel implements ListCellRenderer<Object> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MyCellRenderer() {
		setOpaque(true);
	}

	@Override
	public Component getListCellRendererComponent(JList<?> list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {

		setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));

		if (value != null) {
			setText(((FriendInfo) value).getName());
			ImageIcon ii = new ImageIcon("resources/img/"
					+ ((FriendInfo) value).getImgPath());
			setIcon(ii);
		}

		setForeground(new Color(169, 172, 173));
		if (isSelected) {
			setBackground(new Color(65, 73, 84));
			setForeground(new Color(255, 255, 255));
//			setForeground(list.getSelectionForeground());
		} else {
			// 设置选取与取消选取的前景与背景颜色.
			setBackground(list.getBackground());
//			setForeground(list.getForeground());
		}

		return this;
	}

}
